# 下面是一个重写了特殊方法 __getattribute__ 的类装饰器，可以打印日志:
def defindAttribute(cls):
    origin_getattribute=cls.__getattribute__


    def new_getattribute(self,name):
        print('greeting:',name)

        if  name == "label_columns":
            cols = origin_getattribute(self ,"datamodel").list_columns
            return getDict(cols)
        elif name == "edit_columns" or name == "add_columns" or name == "list_columns" or name == "show_columns":
            cols = origin_getattribute(self, "datamodel").list_columns
            return list(getDict(cols).keys())
        return origin_getattribute(self,name)

    cls.__getattribute__=new_getattribute
    return cls

def getDict(cols):
    dict = {}
    for col in cols:
        if (len(cols[col].foreign_keys) != 0 and cols[col].comment is not None):
            for fk in cols[col].foreign_keys:
                dict.__setitem__(fk._colspec.split('.')[0], cols[col].comment)
        elif (cols[col].comment is not None):
            dict.__setitem__(col, cols[col].comment)
    return dict